package com.qiahao.controller;

import com.qiahao.dto.PageDTO;
import com.qiahao.bean.Phone;
import com.qiahao.service.ImportExcelService;
import com.qiahao.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;


@Controller
@RequestMapping("/phone")
public class PhoneController {

    @Autowired
    ImportExcelService importExcelService;

    @Autowired
    VoiceService voiceService;


    @ResponseBody
    @RequestMapping(value = "uploadPayerCreditInfoExcel", method = {RequestMethod.GET, RequestMethod.POST})
    public PageDTO<Phone> uploadPayerCreditInfoExcel(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("upfile");
        PageDTO<Phone> data = importExcelService.importExcel(file);

        return data;
    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public PageDTO<Phone> getPhoneList(Integer p, Integer step) {
        if (p == null) {
            p = 1;
        }
        if (step == null) {
            step = 10;
        }
        return importExcelService.getPhoneList(p, step);

    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> addPhone(Phone phone) {

        return importExcelService.addPhone(phone);

    }
}
